<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h2>总价格：{{totalprice}}</h2>

    </div>
    <script src="vue.js"></script>
    <script>
        app = new Vue({
            //声明要绑定的id
            el:'#app',  
            //数据对象 
            data:{
                books: [
                    {id: 110, name: 'Unix编程艺术',price:119 },
                    {id: 111, name:'代码大全',price: 105 },
                    {id: 112, name: '深入理解计算机原理',price: 98},
                    {id: 113, name: '现代操作系统',price: 87 }
                ]
            },
            computed:{
                totalprice: function(){
                     let result = 0;
                    for (let n=0;n < this.books.length;n++){
                        result = result + this.books[n].price
                    }
                    return result
                }
            },

            //methods用于定义方法
            methods: {

            }
        })
    </script>
</body>
</html>